<?php
class chapter extends Model
{
    public $id;
	public $programme_id;
	public $episode_id;
	public $onair_episode_no;
	public $video_id;
	public $infos;
	public $in_time;
	public $out_time;
	public $primary_category_id;
	public $category_list;
	public $publish_datetime;
	public $expire_datetime;
	public $country_allow_list;
	public $country_deny_list;
	public $created_at;
	public $modified_at;
	public $tag_list;
	public $liberal_tag_list;
	public $ii_data;
	public $title;
	public $title_zh;
	public $title_en;
	public $description;
	public $description_zh;
	public $description_en;
	public $casts;
	public $categories;

    public static function getTableName()
    {
        return 'chapter';
    }

    public function set($obj)
    {
        foreach (get_object_vars($this) as $field=>$value) {
            $this->$field = isset($obj->$field) ? $obj->$field : '';
        }
    }

    public function insert($obj)
    {
        return Model::$dbo['w']->save($obj);
    }

    public function update($obj)
    {
        return Model::$dbo['w']->save($obj);
    }

    public function delete($obj)
    {
        return Model::$dbo['w']->deleteInstance($this->getTableName(),$obj->id);
    }

    public function findChapterNotInId(array $id=array(), $programme_id)
    {
        return Model::$dbo['r']->find(__CLASS__, "programme_id=? AND id NOT IN(" . implode(',', $id) . ")", array($programme_id));
    }
}
?>
